package io.kimmking.chatoom.client.config;

import io.kimmking.chatoom.client.boot.NettyClientBootStrap;
import io.kimmking.chatoom.client.handler.NettyClientMsgHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;

@Configuration
public class NettyClientAutoConfigure {

    /**
     * 启动NettyClient，连接NettyServer，发起聊天操作
     * @param nettyClientMsgHandler
     * @return
     */
    @Bean(destroyMethod = "close")
    @ConditionalOnBean(NettyClientMsgHandler.class)
    @ConditionalOnMissingBean
    public NettyClientBootStrap nettyClientBootStrap(final NettyClientMsgHandler nettyClientMsgHandler){

        return new NettyClientBootStrap(nettyClientMsgHandler);

    }
}